/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;

/**
 * @author zl
 *
 */
public class MetaPackageFigure extends CommonFigure {
	Label nameLabel;
	int headerHeight = 15;
	PointList vertices;
	public MetaPackageFigure() {
		setBorder(new MarginBorder(headerHeight));
		setOpaque(true);
		ToolbarLayout layout = new ToolbarLayout();
		layout.setSpacing(2);
		setLayoutManager(layout);
		
		nameLabel = new Label();
//		setBackgroundColor(new Color(null,230,255,128));
		setBackgroundColor(new Color(null,255,255,255));
		vertices = new PointList();
		add(nameLabel);
		
	}
	@Override
	protected void paintShadow(Graphics g) {
		g.pushState();
		Rectangle rect = getBounds().getCopy().translate(3, 3);
		g.setClip(rect);
		g.setBackgroundColor(ColorConstants.buttonDarker);
		PointList newV = vertices.getCopy();
		newV.translate(3, 3);
		g.fillPolygon(newV);
		g.popState();
	}
	
	@Override
	protected void paintFigure(Graphics g) {
		Point pt = this.getLocation();
		Dimension size = this.getSize();
		int headerWidth = size.width/3;
		vertices.removeAllPoints();
		vertices.addPoint(pt);
		vertices.addPoint(pt.x+headerWidth, pt.y);
		vertices.addPoint(pt.x+headerWidth, pt.y+headerHeight);
		vertices.addPoint(pt.x+size.width-1, pt.y+headerHeight);
		vertices.addPoint(pt.x+size.width-1, pt.y+size.height-1);
		vertices.addPoint(pt.x, pt.y+size.height-1);

		paintShadow(g);
		
		g.pushState();
		g.setBackgroundColor(ColorConstants.white);
		g.fillRectangle(pt.x, pt.y, headerWidth, headerHeight);
		g.popState();
		
		g.pushState();
		g.setForegroundColor(ColorConstants.white);
		g.fillGradient(pt.x, pt.y+headerHeight, size.width, size.height-headerHeight, true);
		g.popState();
		g.drawPolygon(vertices);
	}
	/**
	 * @return Returns the nameLabel.
	 */
	public Label getNameLabel() {
		return nameLabel;
	}
	/**
	 * @param nameLabel The nameLabel to set.
	 */
	public void setNameLabel(Label nameLabel) {
		this.nameLabel = nameLabel;
	}
}

//class PackageHeader extends Figure{
//	protected void paintFigure(Graphics g) {
//		Point pt = this.getLocation();
//		Dimension size = this.getSize();
//		g.drawLine(pt.x, pt.y, pt.x+size.width, pt.y);
//		g.drawLine(pt.x, pt.y, pt.x, pt.y+size.height);
//		g.drawLine(pt.x+size.width, pt.y, pt.x+size.width, pt.y+size.height);
//	}
//}
